﻿@{
    Layout = null;
}
@model ElingOA6_Admin_DSJCJ.Model.CdTaskClass
<!DOCTYPE html>
<html>
 @Html.Partial("LoadPanelPartial")
<head>
    <title></title>
    @if (false)
    {
        <script src="../../../../Scripts/jquery-vsdoc.js" type="text/javascript"></script>
        <script src="../../../../Scripts/ASPxScriptIntelliSense.js" type="text/javascript"></script>
    }
  <link href="@Url.Content("~/Content/Site.css", true)" rel="stylesheet" type="text/css" />

    <script src="@Url.Content("~/Scripts/jquery.min.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/FloatDiv.js", true)" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/regex.js", true)" type="text/javascript"></script>
    <script src="@Url.Content("~/Common/GetRootPath.ashx", true)" type="text/javascript"></script>

   @Html.DevExpress().GetStyleSheets(

    new StyleSheet { ExtensionType = ExtensionType.ListBox, Theme = DevExpressHelper.Theme }
    )
    @Html.DevExpress().GetScripts(
        new Script { ExtensionType = ExtensionType.ListBox }
    )

    <script type="text/javascript">
        $(document).ready(function () {
            $("#toolMenu").smartFloat();
            var hdjsAlert = $("#hdjsAlert").val();
            if (hdjsAlert != "") {
                alert(hdjsAlert);
            }
        });
        /*保存*/
        function save() {
            if (FTaskClassCd.GetText() == "") {
                alert("任务类别编码不能为空");
                FTaskClassCd.Focus();
                return;
            }
            if (FTaskClassName.GetText() == "") {
                alert("任务类别名称不能为空");
                FTaskClassName.Focus();
                return;
            }
            if (FScore.GetText() == "") {
                alert("默认分值不能为空");
                FScore.Focus();
                return;
            }

            checkedNodes = new Array();
            ListCheckedOrgUserNodes(djUserTree);
            $("#hddjUserSelect").val(checkedNodes.join(","));
           // var aa = checkedNodes.join(",");
            checkedNodes = new Array();
            ListCheckedOrgUserNodes(spUserTree);
            $("#hdspUserSelect").val(checkedNodes.join(","));
            lpModal.Show();
            form1.submit();

        }
        /*增加*/
        function addTaskClass() {
            lp.Show();
            window.location.href = rootPath + "/Admin/TaskClass/AddTaskClass";
        }
        /*删除*/
        function deleteTaskClass() {
            var taskClassName = FTaskClassName.GetText();
            var hdFTaskClassCdEn = $("#hdFTaskClassCdEn").val();
            if (confirm("确定删除【" + taskClassName + "】吗？")) {
                $.ajax({
                    type: "POST",
                    url: rootPath + "/Admin/TaskClass/DeleteTaskClass",
                    data: { FTaskClassCdEn: hdFTaskClassCdEn },
                    async: true,
                    success: function (jsonstr) {
                        var msg = jsonstr.split('|');
                        if (msg[0] == "ok") {
                            alert("删除成功");
                            parent.afterDeleteNode();
                        }
                        else {

                            alert("删除失败");
                            
                        }
                    }
                });
            }
        }
        var checkedNodes;
        /*用户树*/
        function ListCheckedOrgUserNodes(parent) {
            for (var i = 0; i < parent.GetNodeCount(); i++) {
                if (parent.GetNode(i).GetChecked()) {
                    var node = parent.GetNode(i);
                    var nodeids = node.name.split("|");
                    if (nodeids.length > 1) {
                        if (nodeids[0] == "user") {
                            checkedNodes.push(nodeids[1]);
                        }
                    }
                }
                if (parent.GetNode(i).GetNodeCount() != 0) {
                    ListCheckedOrgUserNodes(parent.GetNode(i));
                }
            }
        }
        

        /*节点选中*/
        function orgUserTreeInit() {
            var node = spUserTree.GetSelectedNode();
            var loginIDs = $("#hdsploginIDs").val();
            if (loginIDs != "") {
                var loginIDArray = loginIDs.split(",");
                for (var i = 0; i < loginIDArray.length; i++) {
                    var node = spUserTree.GetNodeByName("user|" + loginIDArray[i]);
                    if (node) {
                        node.SetChecked(true);
                    }
                }
            }
        }
        function functionTreeInit() {
            var node = djUserTree.GetSelectedNode();
            var loginIDs = $("#hddjloginIDs").val();
            if (loginIDs != "") {
                var loginIDArray = loginIDs.split(",");
                for (var i = 0; i < loginIDArray.length; i++) {
                    var node = djUserTree.GetNodeByName("user|" + loginIDArray[i]);
                    if (node) {
                        node.SetChecked(true);
                    }
                }
            }
        }
        function MenuTop_emClick(source, e) {
            switch (e.item.name) {
                case "btnSave":
                    {
                        //保存
                        save();
                        break;
                    }
                case "btnAdd":
                    {
                        //增加同级
                        addTaskClass();
                        break;
                    }

                case "btnDelete":
                    {
                        //删除
                        deleteTaskClass();
                        break;
                    }
            }
        }
    </script>

</head>
<body>
    @using (Html.BeginForm("Save", "TaskClass", FormMethod.Post, new { id = "form1", @class = "edit_form" }))
    {
           <div class="floatToolMenu" id="toolMenu">
        @Html.DevExpress().Menu(settings =>
   {
       settings.Name = "toolBarMenu";
       settings.ItemAutoWidth = false;
       settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
       settings.Styles.Style.Border.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(0);
       settings.Styles.Style.BorderTop.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);
       settings.Items.Add(item =>
       {
           item.Name = "btnSave";
           item.Text = "保存";
           item.ClientEnabled = true;
           item.Image.Url = Url.Content("~/Content/ControlImages/filesave.png");
          
       });
       settings.Items.Add(item =>
       {
           item.Name = "btnAdd";
           item.Text = "新增";
           item.ClientEnabled = true;
           item.Image.Url = Url.Content("~/Content/ControlImages/edit_add.png");

       });
       settings.Items.Add(item =>
       {
           item.Name = "btnDelete";
           item.Text = "删除";
           item.ItemStyle.ForeColor = System.Drawing.Color.Red;
           item.ClientEnabled = true;
           item.Image.Url = Url.Content("~/Content/ControlImages/cancel.png");

       });
       settings.ClientSideEvents.ItemClick = "function(source,e){MenuTop_emClick(source,e)}";
       settings.ItemLinkMode = ItemLinkMode.ContentBounds;
   }).GetHtml()
   </div>
        <div>
            <table align="center" class="tableFrom">
                <tr>
                    <th>
                        <font color='red'>*</font>@Html.DevExpress().Label(settings => { settings.Text = "任务类别编码:"; }).GetHtml()
                    </th>
                    <td>
                        @Html.DevExpress().TextBox(settings =>
                   {
                       settings.Name = "FTaskClassCd";
                       settings.Width = 100;
                       settings.Text = Model.FTaskClassCd;
                       settings.ReadOnly = Model.FTaskClassCd != null ? true : false;
                   }).GetHtml()
                    </td>
                    <th>
                        <font color='red'>*</font>@Html.DevExpress().Label(settings => { settings.Text = "任务类别名称:"; }).GetHtml()
                    </th>
                    <td>
                        @Html.DevExpress().TextBox(settings =>
                   {
                       settings.Name = "FTaskClassName";
                       settings.Width = 220;
                       settings.Text = Model.FTaskClassName;
                   }).GetHtml()
                    </td>
                    <th>
                        @Html.DevExpress().Label(settings => { settings.Text = "默认分值:"; }).GetHtml()
                    </th>
                    <td>
                        @Html.DevExpress().TextBox(settings =>
                   {
                       settings.Name = "FScore";
                       settings.Width = 100;
                       settings.Text = Model.FScore.ToString();
                   }).GetHtml()
                    </td>
                </tr>
            </table>
        </div>
        @Html.DevExpress().PageControl(
    settings =>
    {
        settings.Name = "tabCtlGroup";
        settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
        //settings.Height = System.Web.UI.WebControls.Unit.Pixel(600);
        settings.Styles.Content.Border.BorderWidth = 0;
        settings.TabPages.Add("登记权限").SetContent(() =>
        {
            @Html.DevExpress().TreeView(settingsGroupUser =>
            {
                settingsGroupUser.Name = "djUserTree";
                settingsGroupUser.ShowTreeLines = true;
                settingsGroupUser.AllowSelectNode = true;
                settingsGroupUser.NameField = "Id";
                settingsGroupUser.TextField = "Name";
                settingsGroupUser.ImageUrlField = "ImageUrl";
                settingsGroupUser.CheckNodesRecursive = true;
                settingsGroupUser.AllowCheckNodes = true;
                settingsGroupUser.AllowSelectNode = false;
                settingsGroupUser.ClientSideEvents.Init = "function(s, e) { functionTreeInit(s,e) }";
                settingsGroupUser.EnableAnimation = false;
                settingsGroupUser.EnableClientSideAPI = true;
                settingsGroupUser.PreRender = (source, e) =>
                {
                    ASPxTreeView treeView = (ASPxTreeView)source;
                    
                };
            }).Bind(ViewData["treeModelUserList"]).GetHtml();
        });
        settings.TabPages.Add("审批权限").SetContent(() =>
        {
            @Html.DevExpress().TreeView(settingsGroupUser =>
            {
                settingsGroupUser.Name = "spUserTree";
                settingsGroupUser.ShowTreeLines = true;
                settingsGroupUser.AllowSelectNode = true;
                settingsGroupUser.NameField = "Id";
                settingsGroupUser.TextField = "Name";
                settingsGroupUser.ImageUrlField = "ImageUrl";
                settingsGroupUser.CheckNodesRecursive = true;
                settingsGroupUser.AllowCheckNodes = true;
                settingsGroupUser.AllowSelectNode = false;
                settingsGroupUser.ClientSideEvents.Init = "function(s, e) { orgUserTreeInit(s,e) }";
                settingsGroupUser.EnableAnimation = false;
                settingsGroupUser.PreRender = (source, e) =>
                {
                    ASPxTreeView treeView = (ASPxTreeView)source;
                    

                };
            }).Bind(ViewData["treeModelUserList"]).GetHtml();
        });

    }).GetHtml()

        @Html.Hidden("hdtaskClassCd", ViewData["taskClassCd"]);
        @Html.Hidden("hddjUserSelect", "");
        @Html.Hidden("hdspUserSelect", "");
        @Html.Hidden("hdMethod", ViewData["hdMethod"]);
        @Html.Hidden("hdjsAlert", (ViewData["jsAlert"]));
        @Html.Hidden("hddjloginIDs", (ViewData["djloginIDs"]));
        @Html.Hidden("hdsploginIDs", (ViewData["sploginIDs"]));                                          
        @Html.Hidden("hdFocusKey", ViewData["focusKey"]);
        @Html.Hidden("hdFTaskClassCdEn", Model.FTaskClassCdEn);
    }

    <script type="text/javascript" language="javascript">
        lp.Hide();
    </script>

</body>
</html>
